home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol086 / roff42.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-12-15  |  4.5 KB  |  193 lines

  1. /********************************************************/
  2. /*                            */
  3. /*            ROFF4, Version 1.60            */
  4. /*                            */
  5. /*(C) 1983,4 by Ernest E. Bergmann            */
  6. /*        Physics, Building #16            */
  7. /*        Lehigh Univerisity            */
  8. /*        Bethlehem, Pa. 18015            */
  9. /*                            */
  10. /* Permission is hereby granted for all commercial and    */
  11. /* non-commercial reproduction and distribution of this    */
  12. /* material provided this notice is included.        */
  13. /*                            */
  14. /********************************************************/
  15. /*feb 19, 1984*/
  16. /*Jan 14, 1984*/
  17. /********************************************************/
  18. /* March 1984  DeSmet C version */
  19. /* Henry Harpending*/
  20. /* Anthropology Department*/
  21. /* University of New Mexico*/
  22. /* Albuquerque, NM  87131*/
  23. /*   no restrictions */
  24. /*********************************************************/
  25. #include "a:roff4.h"
  26.  
  27. insert()    /*takes a command line in LINE and adds its
  28.         entry to the table; no space check is made of
  29.         TRTBL*/
  30. {int *pw;
  31. char *pc,*s2,*s3,*fnd;
  32. pw=TREND;
  33. *pw=SLINK;
  34. pc=pw+1;
  35. gettl3(LINE,pc,&s2,&s3);
  36. if(fnd=find2(pc,SLINK))
  37.     {fprintf(stderr,"%cWarning: <%s> was defined to be <%s>\n",BELL,pc,fnd);
  38.     fprintf(stderr,"...now it is defined to be <%s>\n",s2);
  39.     }
  40. SLINK=TREND;
  41. TREND=s3;
  42. }
  43. /****************************************/
  44. showit()    /* displays the list of entries in the string
  45.         substitution table pointed to by HEAD. */
  46. {int *pw;
  47. char *pc;
  48. fprintf(stderr,"ENTRIES:\n");
  49. pw=SLINK;
  50. while(pw)
  51.     {fprintf(stderr,"%u: ",pw);
  52.     pc=pw+1;
  53.     fprintf(stderr,"<%s>",pc);
  54.     pc += strlen(pc); pc++;
  55.     if(*pc) fprintf(stderr," <%s>\n",pc);
  56.     else fprintf(stderr," <>\n"); /*'C' bug*/
  57.     pw=*pw;
  58.     }
  59. dashes();
  60. }
  61. /****************************************/
  62. putback(c)    /*cf K & P, p256*/
  63. char c;
  64. {if(++BINP >= BACKSIZE)
  65.     {printf(stderr,"Too many characters pushed back\n");
  66.     exit();
  67.     }
  68. BACKBUF[BINP]=c;
  69. }
  70. /****************************************/
  71. int ngetc(iobuf)    /*cf K & P p256*/
  72. FILE iobuf;    /*filters \r followed by \n,msb*/
  73. {int kgetc(), c;
  74. if(BINP) c=BACKBUF[BINP];
  75. else    {if(KEYBD){
  76.      c=kgetc();
  77.       if (c==EOF) return(EOF);
  78. }      
  79. else if (((c=getc(iobuf)) == EOF) ||(c== CPMEOF)){
  80.     BACKBUF[BINP=1]=CPMEOF;
  81.     return EOF;
  82. }
  83.     else c&=0x7f;
  84.     BACKBUF[BINP=1]=c;
  85.     }
  86. if((c!=CPMEOF)&&c!=EOF) BINP--;
  87. if (c==CPMEOF) c=EOF;
  88. if(c=='\r')
  89.     {c=ngetc(iobuf);
  90.     if(c!='\n')
  91.         {putback(c);
  92.         return('\r');
  93.         }
  94.     }
  95. return(c);
  96. }
  97. /****************************************/
  98. kgetc()    /*like getc(),from keyboard, line-buffered*/
  99. {int i;
  100. if(!*KPTR)
  101.     {fprintf(stderr,"%c",KEYBD);
  102.     if((gets(KLINE)) == NULL) return EOF;
  103.     i=strlen(KLINE);
  104.     KLINE[i++]='\n';
  105.     KLINE[i]='\0';
  106.     KPTR=KLINE;
  107.     }
  108. return(*(KPTR++));
  109. }
  110. /****************************************/
  111. pbstr(s)    /*put back string on input;cf K&P,p257*/
  112. char s[LSZ];
  113. {int i;
  114. for(i=strlen(s);i>0;) putback(s[--i]);
  115. }
  116. /****************************************/
  117. minsert()    /*takes a .DM and following lines and places
  118.         the information in the table;  no macro
  119.         definition nesting permitted*/
  120. {char c, *pc,*pc2;
  121. int *pw1;
  122. /*pass over command and following white space*/
  123. for(pc=LINE,c=*pc; (c!=' ')&&(c!='\n')&&(c!='\t'); pc++)
  124.     c=*pc;
  125. for(; (c==' ')||(c=='\t'); pc++) c=*pc;
  126. start();
  127. if(c=='\n') {fprintf(stderr,".DM is UNnamed\n"); }
  128. else    {pw1=TREND;
  129.     *(pw1++)=MLINK;
  130.     MLINK=TREND;
  131.     TREND=pw1;
  132.     while(class(c)==BLACK)
  133.         {*(TREND++)=c;
  134.         c=*(pc++);
  135.         }
  136.     }
  137. *(TREND++)='\0';
  138. while(fgets2(LINE,ifp))    /*until EOF or CPMEOF*/
  139.     {pw1=LINE;
  140.     if((*LINE==COMMAND)&&(comtyp(LINE)==EM)) break;
  141.     else    {transfer(&pw1,&TREND,0);
  142.         *(TREND-1)='\n';
  143.         }
  144.     }
  145. *(TREND++)='\0';
  146. complete();
  147. }
  148. /****************************************/
  149. showm()    /*lists macro definitions*/
  150. {int *pw;
  151. char *pc;
  152. fprintf(stderr,"MACROS DEFINED:\n");
  153. pw=MLINK;
  154. while(pw)
  155.     {pc = pw+1;
  156.     fprintf(stderr,"%u  .%s\n",pw,pc);
  157.     pc +=strlen(pc); pc++;
  158.     fprintf(stderr,"%s\n",pc);
  159.     pw=*pw;
  160.     }
  161. dashes();
  162. }
  163. /****************************************/
  164. char *macq(line)    /*looks up name to see if it is a macro
  165.             definition.  If it is, returns the
  166.             corresponding string, else returns
  167.             FALSE.
  168.             */
  169. char *line;
  170. {char c,*pc,wb[LSZ],*find2();
  171. pc=wb;
  172. while(class(c=*(++line))==BLACK) *(pc++)=c;
  173. *pc='\0';
  174. return(find2(wb,MLINK));
  175. }
  176. /****************************************/
  177. char *find2(s,link)    /*finds or doesn't find s in table
  178.             of substitutions pointed to by link*/
  179. char *s;
  180. int *link;
  181. {char *pc;
  182. while(link)
  183.     {if(!strcmp(s,link+1))
  184.         {pc=link+1;
  185.         pc += strlen(pc);
  186.         pc++;
  187.         return(pc);
  188.         }
  189.     link=*link;
  190.     }
  191. return(FALSE);
  192. }
  193.